var zTreeObj;
function initPage() {
    getModuleOperationByUserDMAndModuleDM(parent.parent.session.USER_DM, myTools.getQueryString("MODULE_DM"), '1', "securityDIV");
    //取模块权限按钮
    getItemTree();
}
function getItemTree() {

    var json = {
        url:contextPath + "/server/site/getSiteItemTree.do",
        msg:"数据加载中.....",
        params:{

        },
        callback:[getItemTreeCallBack]
    };
    AjaxTools.ajax(json);

}
function getItemTreeCallBack(result) {
    var setting = {
        data:{
            simpleData:{
                enable:true,
                idKey:"id",
                pIdKey:"pId",
                rootPId:0
            }
        },
        callback:{
            onClick:function (event, treeId, treeNode, clickFlag) {
                document.getElementById("PID").value = treeNode.id;
                searchSiteItem();
            }
        }
    };
    var zTreeNodes = result.msg;
    zTreeObj = $.fn.zTree.init($("#tree"), setting, zTreeNodes);
}
function searchSiteItem() {
    var json = {
        url:contextPath + "/server/base/select.do",
        msg:"数据加载中.....",
        form:"searchForm",
        params:{
            "SQLID":"site.site_item.getSITE_ITEM",
            "HTML_PATH":"/service/site/site_item/viewList.jsp",
            "RESULT_TYPE":"jsonHtml"
        },
        callback:[searchSiteItemCallBack]
    };
    AjaxTools.ajax(json);
}
/**
 * 翻页
 * @param page
 * @return
 */
function queryPage(page) {
    var json = {
        url:contextPath + "/server/base/select.do",
        msg:"数据加载中.....",
        form:"searchForm",
        params:{
            "SQLID":"site.site_item.getSITE_ITEM",
            "CURPAGE":page,
            "HTML_PATH":"/service/site/site_item/viewList.jsp",
            "RESULT_TYPE":"jsonHtml"
        },
        callback:[searchSiteItemCallBack]
    };
    AjaxTools.ajax(json);
}
function searchSiteItemCallBack(result) {
    if (result.code == "00") {

        document.getElementById("editAreaDiv").innerHTML = result.data;
    } else {
        alert(result.data);
    }
}

/**
 *显示添加栏目窗口
 */
function addItem() {
    win.open('addItem', '添加新闻栏目', '../../../service/site/site_item/addItem.jsp?pid=' + document.getElementById("PID").value, 350, 250, true, true);
}
/**
 *显示修改栏目窗口
 */
function editItem() {
    //var id = myTable.getSelectedID();
    var row = window.row;
    var id = row.getAttribute("id");
    if (id)
        win.open('editUser', '修改新闻栏目', '../../../service/site/site_item/editItem.jsp?ID=' + id, 350, 250, true, true);
}

/**
 * 删除栏目
 */
function delItem() {
    var ids = myTable.getSelectedIDS();
    var row = window.row;
    var id = row.getAttribute("id");
    ids = ids.length==0?id:ids;
    if (ids) {
        if (confirm("是否确认删除？")) {
            var json = {
                url:contextPath + "/server/base/delete.do",
                msg:"数据删除中.....",
                params:{
                    "IDS":ids,
                    "SQLID":"site.site_item.delSITE_ITEM"
                },
                callback:[delItemCallBack]
            };
            AjaxTools.ajax(json);
        }
    }
}
function delItemCallBack(json) {
    var code = json.code;
    if (code == "00") {
        alert(json.data);
        searchSiteItem();
    } else {
        alert(json.data);
    }

}
function updateStatus(flg) {
    var row = window.row;
    var id = row.getAttribute("id");
    if (id) {
        var json = {
            url:contextPath + "/server/base/update.do",
            msg:"数据保存中.....",
            params:{
                "SQLID":"site.site_item.updateSITE_ITEMDynamic",
                "ID":id,
                "STATUS":flg
            },
            callback:[updateStatusCallBack]
        };
        AjaxTools.ajax(json);

    }
}
function updateStatusCallBack(json) {
    var code = json.code;
    if (code == "00") {
        alert("状态更新成功！");
        searchSiteItem();
    } else {
        alert(json.data);
    }
}